/*
 * Copyright (C) 2012 Robot.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.yfz.bussearch.ui;


import com.yfz.bussearch.R;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

public class WebSearch extends Activity {
	
	private final String TAG = this.getClass().getSimpleName();
	
	private final String URL = "http://m.sz-map.com/";
	
	private WebView wv;
	private ProgressBar pb;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.webview);
		
		wv = (WebView)findViewById(R.id.id_webview);
		pb = (ProgressBar)findViewById(R.id.id_progress);
		wv.requestFocus();
		
		WebSettings websetting = wv.getSettings();
		
		websetting.setJavaScriptEnabled(true);
		
		websetting.setSupportZoom(true);
		
		Bundle bundle = this.getIntent().getExtras();
		Log.d(TAG, "Is Bundle NULL? - " + (bundle == null));
		if(bundle != null) {
			String url = bundle.getString("URL");
			Log.d(TAG, "URL= " + url);
			wv.loadUrl(url);
		} else {
			wv.loadUrl(URL);
		}
		
		//不使用系统默认浏览器
		WebViewClient wvc = new WebViewClient() {

			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				wv.loadUrl(url);
				return true;
			}

			@Override
			public void onPageFinished(WebView view, String url) {
				super.onPageFinished(view, url);
				pb.setVisibility(View.GONE);
			}
			
		};
		
		wv.setWebViewClient(wvc);
	}

	@Override
	public void onBackPressed() {
		if(wv.canGoBack()) {
			wv.goBack();
			return;
		}
		super.onBackPressed();
	}
}
